package cachex

import (
	"time"

	"github.com/patrickmn/go-cache"
)

type goCache struct {
	cache *cache.Cache
}

func NewGoCache() Cache {
	return &goCache{
		cache: cache.New(5*time.Minute, 10*time.Minute),
	}
}

func (c *goCache) Set(key, val string, expiration time.Duration) error {
	c.cache.Set(key, val, expiration)
	return nil
}

func (c *goCache) SetNoExpiration(key, val string) error {
	c.Set(key, val, cache.NoExpiration)
	return nil
}

func (c *goCache) Get(key string) (string, error) {
	if val, ok := c.cache.Get(key); ok {
		return val.(string), nil
	}
	return "", nil
}

func (c *goCache) Del(keys ...string) error {
	for _, key := range keys {
		c.cache.Delete(key)
	}
	return nil
}

func (c *goCache) Clear() error {
	c.cache.Flush()
	return nil
}
